//
//  XKOBaseTableViewController.swift
//  sinawb
//
//  Created by Mars on 16/4/9.
//  Copyright © 2016年 Mars. All rights reserved.
//

import UIKit

class XKOBaseTableViewController: UITableViewController  {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    var userLogin = false
    //判断用户是否登录,如果登录了,就走父类的super.loadView加载带数据的tableView 否则就加载登录界面

    //重写loadView 在控制器加载view还没显示的时候调用了
    override func loadView() {
        
        userLogin ? super.loadView() : setUpVisitorView()
        
    }
    
  
    //设置访客视图
    private func setUpVisitorView (){

        view = visitorView
        //代理
        visitorView.delegate = self

        if self is XKOHomeTableViewController{
        
            //设置旋转动画
            visitorView.rotation()
            
        }else if self is XKOMessageTableViewController{
        
           visitorView.changeVisitorView("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        
        }else if self is XKODiscoverTableViewController{
            
        
            visitorView.changeVisitorView("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is XKOProfileTableViewController{
        
            visitorView.changeVisitorView("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnClick")
        
//        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnClick")

        
        //创建注册按钮
        let leftItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnClick")
        self.navigationItem.leftBarButtonItem = leftItem
        leftItem.tintColor = UIColor.orangeColor()
        
        //创建登录按钮
        let rightItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnClick")
        self.navigationItem.rightBarButtonItem = rightItem
        rightItem.tintColor = UIColor.orangeColor()
        
        
        
    }
 

    //创建VisitorView
    private lazy var visitorView:XKOVisitorView = XKOVisitorView()
}


extension XKOBaseTableViewController : XKOVisitorViewDelegate{
    
    //MARK : 代理方法的实现
    func registerBtnClick() {

     print("registerBtnClick")
    }
    
    func loginBtnClick() {
        print("loginBtnClick")
        
        let OauthView = XKOOauthViewController()
        
        OauthView.view.backgroundColor = UIColor.whiteColor()
        
        //包装一个导航控制器
        let nav = UINavigationController(rootViewController: OauthView)
        //modal的形式推出
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
}